/** DoctorInvoicePanel */
package client.ui.panel;

import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.List;

import javax.swing.JLabel;
import javax.swing.JPanel;

import client.ClientManager;
import client.service.AppointmentService;
import domain.appointment.Appointment;
import domain.records.MedicalService;

/**
 * @author jessienewman
 * @version $Revision: 1.0 $
 */
public class DoctorInvoicePanel extends DefaultPanel {
	
	/**
	 * Field c.
	 */
	private GridBagConstraints c;
	
	/**
	 * Field center.
	 */
	private JPanel center;

	/**
	 * Constructor for DoctorInvoicePanel.
	 */
	public DoctorInvoicePanel() {
		center = new JPanel();
		add(center, BorderLayout.CENTER);
		center.setLayout(new GridBagLayout());
	}

	/**
	 * Method updateDoctor.
	 * @param doctorId Integer
	 */
	public void updateDoctor(Integer doctorId) {
		doctorId = ClientManager.SESSION.getUserId(); // $codepro.audit.disable questionableAssignment
		final List<Appointment> appointments = 
			AppointmentService.getLastMonthDoctorAppointments(doctorId);
		c = new GridBagConstraints();

		c.gridx = 0;
		c.gridy = 0;
		c.fill = GridBagConstraints.HORIZONTAL;
		c.gridy++;
		c.gridx = 0;
		if (appointments.size() == 0) {
			center.add(new JLabel("(No appointments last month)"), c);
		} else {
			center.add(new JLabel("Appointments Last Month:"), c);
			c.gridy++;
			center.add(new JLabel("Patient"), c);
			c.gridx++;
			center.add(new JLabel("Date"), c);
			c.gridx++;
			center.add(new JLabel("$Total"), c);
			c.gridx = 0;
			c.gridy++; 
			int total = 0;
			for (Appointment a : appointments) {
				c.gridx = 0;
				center.add(new JLabel(a.getPatient().getFullName()), c);
				c.gridx++;
				center.add(new JLabel(a.getDateString()), c);
				c.gridx++;
				int price = 0;
				for (MedicalService ms : 
					a.getTreatmentRecord().getOrders().getService()) {
					price += ms.getPrice();
					total += ms.getPrice();
				}
				center.add(new JLabel("$" + price), c);
				c.gridy++;
			}
			c.gridx = 0;
			center.add(new JLabel(""), c);
			c.gridy++;
			center.add(new JLabel("Total: $" + total), c);
		}
		c.gridx = 0;
		c.gridy++;
	}
}
